Show the code
pacman::p_load(jsonlite, tidygraph, ggraph, dplyr,
visNetwork, graphlayouts, ggforce, knitr, kableExtra,
skimr, tidytext, tidyverse, igraph, ggplot2, RColorBrewer)ggplot(mc3_df,aes(x = type, y = betweenness_centrality)) + # Draw ggplot2 boxplot
geom_boxplot() +
stat_summary(fun = mean, geom = "point", col = "red") + # Add points to plot
stat_summary(fun = mean, geom = "text", col = "red", # Add text to plot
vjust = 1.5, aes(label = paste("Mean:", round(..y.., digits = 1))))
library(dplyr)
library(tidyr)
# Calculate mean and quartiles
mean_betweenness <- mean(mc3_df$betweenness_centrality, na.rm = TRUE)
quartiles_betweenness <- quantile(mc3_df$betweenness_centrality, probs = c(0.5,0.9,0.95,0.99), na.rm = TRUE)
max_betweenness <- max(mc3_df$betweenness_centrality, na.rm = TRUE)
mean_degree <- mean(mc3_df$degree_centrality, na.rm = TRUE)
quartiles_degree <- quantile(mc3_df$degree_centrality, probs = c(0.50,0.90,0.95), na.rm = TRUE)
max_degree <- max(mc3_df$degree_centrality, na.rm = TRUE)# Create a data frame for betweenness centrality
betweenness_df <- data.frame(
Measure = c("Mean", "Quartile 0.50 (Median)", "Quartile 0.90", "Quartile 0.95", "Quartile 0.99", "Maximum"),
Value = c(mean_betweenness, quartiles_betweenness, max_betweenness)
)
# Create a data frame for degree centrality
degree_df <- data.frame(
Measure = c("Mean", "Quartile 0.50 (Median)", "Quartile 0.90","Quartile 0.95","Maximum"),
Value = c(mean_degree, quartiles_degree,max_degree)
)| Measure | Value |
|---|---|
| Mean | 8393.619 |
| Quartile 0.50 (Median) | 0.000 |
| Quartile 0.90 | 3.000 |
| Quartile 0.95 | 176.400 |
| Quartile 0.99 | 165050.000 |
| Maximum | 3849384.703 |
| Measure | Value |
|---|---|
| Mean | 1.287965 |
| Quartile 0.50 (Median) | 1.000000 |
| Quartile 0.90 | 2.000000 |
| Quartile 0.95 | 3.000000 |
| Maximum | 120.000000 |
nodes_top_betweenness <- nodes_top_betweenness %>% mutate(group = ifelse(is.na(type), "NA", type))
vis_plot <- visNetwork(nodes_top_betweenness, edges_top_betweenness,
main = "Interactive Network Graph")%>%
visIgraphLayout(layout = "layout_with_kk", smooth = FALSE,
physics = TRUE
) %>%
visNodes(size = 50, label=nodes_top_betweenness$label) %>%
visEdges(color = list(highlight = "lightgray"), arrows = 'to') %>%
visOptions(selectedBy = "type",
highlightNearest = list(enabled = TRUE,
degree = 1,
hover = TRUE,
labelOnly = TRUE),
nodesIdSelection = TRUE) %>%
visGroups(groupname = "Company", color = "lightblue") %>%
visGroups(groupname = "Company Contacts", color = "salmon") %>%
visGroups(groupname = "Beneficial Owner", color = "yellow") %>%
visGroups(groupname = "NA", color = "grey") %>%
visLegend(width = 0.1) %>%
visPhysics(repulsion = list(springlength = 50),
maxVelocity = 2,
solver = "forceAtlas2Based",
forceAtlas2Based = list(gravitationalConstant = -1000),
timestep = 0.25) %>%
visLayout(randomSeed=4)
vis_plotnodes_top_degree <- nodes_top_degree %>% mutate(group = ifelse(is.na(type), "NA", type))
vis_plot <- visNetwork(nodes_top_degree, edges_top_degree,
main = "Interactive Network Graph")%>%
visIgraphLayout(layout = "layout_with_kk", smooth = FALSE,
physics = TRUE
) %>%
visNodes(size = 50, label=nodes_top_degree$label) %>%
visEdges(color = list(highlight = "lightgray"), arrows = 'to') %>%
visOptions(selectedBy = "type",
highlightNearest = list(enabled = TRUE,
degree = 1,
hover = TRUE,
labelOnly = TRUE),
nodesIdSelection = TRUE) %>%
visGroups(groupname = "Company", color = "lightblue") %>%
visGroups(groupname = "Company Contacts", color = "salmon") %>%
visGroups(groupname = "Beneficial Owner", color = "yellow") %>%
visGroups(groupname = "NA", color = "grey") %>%
visLegend(width = 0.1) %>%
visPhysics(repulsion = list(springlength = 50),
maxVelocity = 2,
solver = "forceAtlas2Based",
forceAtlas2Based = list(gravitationalConstant = -1000),
timestep = 0.25) %>%
visLayout(randomSeed=4)
vis_plotmean_counts <- mean(owner_count$count, na.rm = TRUE)
quartiles_counts <- quantile(owner_count$count, probs = c(0.5,0.95), na.rm = TRUE)
# Create a data frame for betweenness centrality
count_df <- data.frame(
Measure = c("Mean", "Quartile 0.50 (Median)", "Quartile 0.95"),
Value = c(mean_counts, quartiles_counts)
)
count_df %>%
kbl() %>%
kable_paper("hover", full_width = F) %>%
row_spec(0, bold = T, color = "white", background = "#D7261E")| Measure | Value | |
|---|---|---|
| Mean | 3.472574 | |
| 50% | Quartile 0.50 (Median) | 3.000000 |
| 95% | Quartile 0.95 | 5.000000 |